<!DOCTYPE html>
<html lang="zh-cn">
   <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>{$CONF['mallTitle']}后台管理中心</title>
      <link href="__PUBLIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <link href="__CSS__/AdminLTE.css" rel="stylesheet" type="text/css" />
      <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.min.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
      <![endif]-->
      <script src="__PUBLIC__/js/jquery.min.js"></script>
      <script src="__PUBLIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
      <script src="__PUBLIC__/js/common.js"></script>
      <script src="__PUBLIC__/plugins/plugins/plugins.js"></script>



       <!--时间日历插件-->
       <script type="text/javascript" src="__PUBLIC__/plugins/jeDate/jedate.js"></script>
       <script src="__PUBLIC__/plugins/layer/layer.min.js"></script>

       <style>
           .datainp{ width:150px; }
           ul,li,dl,dd,dt{
               list-style-type: none;
           }
       </style>
      <style type="text/css">
		#preview{border:1px solid #cccccc; background:#CCC;color:#fff; padding:5px; display:none; position:absolute;}
	  </style>
       <script src="__PUBLIC__/js/common.js"></script>
   </head>

   <script>

       function notPass(seckillId) {
           var w = layer.open({
               type: 1,
               title:"提交原因",
               shade: [0.6, '#000'],
               border: [0],
               content: '<textarea id="rejectionRemarks" rows="8" style="width:96%;margin:2% 2%;" maxLength="100"></textarea>',
               area: ['500px', '250px'],
               btn: ['提交', '关闭窗口'],
               yes: function(index, layero){
                   var rejectionRemarks = $.trim($('#rejectionRemarks').val());
                   if(rejectionRemarks==''){
                       WST.msg('请输入不通过的原因 !', {icon: 5});
                       return;
                   }
                   var ll = layer.load('数据处理中，请稍候...');
                   $.post("{:U('Admin/Seckill/seckillNotPass')}",{seckillId:seckillId,rejectionRemarks:rejectionRemarks},function(data){
                       layer.close(w);
                       layer.close(ll);
                       var json = WST.toJson(data);
                       if(json==1){
                           WST.msg('操作成功!', {icon: 5});
                           location.reload();
                       }else{
                           WST.msg('操作失败!', {icon: 5});
                       }
                   });
               }
           });
       }
   function changeStatus(id,v){
	   Plugins.waitTips({title:'信息提示',content:'正在操作，请稍后...'});
	   $.post("{:U('Admin/Seckill/changePenddingGoodsStatus')}",{id:id,status:v},function(data,textStatus){
				var json = WST.toJson(data);
				if(json.status=='1'){
					Plugins.setWaitTipsMsg({content:'操作成功',timeout:1000,callback:function(){
					    location.reload();
					}});
				}else if(json.status=='2'){
                    Plugins.closeWindow();
                    Plugins.Tips({title:'信息提示',icon:'error',content:'结束时间不得小于开始时间!',timeout:1000});
				}else{
                    Plugins.closeWindow();
                    Plugins.Tips({title:'信息提示',icon:'error',content:'操作失败!',timeout:1000});
                }
	   });
   }
   $.fn.imagePreview = function(options){
		var defaults = {}; 
		var opts = $.extend(defaults, options);
		var t = this;
		xOffset = 5;
		yOffset = 20;
		if(!$('#preview')[0])$("body").append("<div id='preview'><img width='200' src=''/></div>");
		$(this).hover(function(e){
			   $('#preview img').attr('src',"__ROOT__/"+$(this).attr('img'));      
			   $("#preview").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").show();      
		  },
		  function(){
			$("#preview").hide();
		}); 
		$(this).mousemove(function(e){
			   $("#preview").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
		});
	}
   function getAreaList(objId,parentId,t,id){
	   var params = {};
	   params.parentId = parentId;
	   $('#'+objId).empty();
	   if(t<1){
		   $('#areaId2').html('<option value="">请选择</option>');
		   if(parentId==0)return;
	   }
	   var html = [];
	   $.post("{:U('Admin/Areas/queryByList')}",params,function(data,textStatus){
		    html.push('<option value="">请选择</option>');
			var json = WST.toJson(data);
			if(json.status=='1' && json.list.length>0){
				var opts = null;
				for(var i=0;i<json.list.length;i++){
					opts = json.list[i];
					html.push('<option value="'+opts.areaId+'" '+((id==opts.areaId)?'selected':'')+'>'+opts.areaName+'</option>');
				}
			}
			$('#'+objId).html(html.join(''));
	   });
   }
   function getCatList(objId,parentId,t,id){
	   var params = {};
	   params.id = parentId;
	   $('#'+objId).empty();
	   if(t<1){
		   $('#goodsCatId3').empty();
		   $('#goodsCatId3').html('<option value="0">请选择</option>');
		   if(parentId==0){
			   $('#goodsCatId2').html('<option value="0">请选择</option>');
			   return;
		   }
	   }
	   var html = [];
	   $.post("{:U('Home/GoodsCats/queryByList')}",params,function(data,textStatus){
		    html.push('<option value="0">请选择</option>');
			var json = WST.toJson(data);
			if(json.status=='1' && json.list){
				var opts = null;
				for(var i=0;i<json.list.length;i++){
					opts = json.list[i];
					html.push('<option value="'+opts.catId+'" '+((id==opts.catId)?'selected':'')+'>'+opts.catName+'</option>');
				}
			}
			$('#'+objId).html(html.join(''));
	   });
  }
  $(document).ready(function(){
	    $('.imgPreview').imagePreview();
	    <notempty name='areaId1'>
		getAreaList("areaId2",'{$areaId1}',0,'{$areaId2}');
		</notempty>
		<if condition="$goodsCatId1  neq 0 ">
		getCatList("goodsCatId2",{$goodsCatId1},0,{$goodsCatId2});
		</if>
		<if condition="$goodsCatId2 neq 0 ">
		getCatList("goodsCatId3",{$goodsCatId2},1,{$goodsCatId3});
		</if>
  });
   </script>
   <body class='wst-page'>
    <form method='post' action='{:U("Admin/Seckill/queryPenddingByPage")}'>
       <div class='wst-tbar'> 
      地区：<select id='areaId1' name='areaId1' onchange='javascript:getAreaList("areaId2",this.value,0)'>
               <option value=''>请选择</option>
               <volist name="areaList" id="vo">
               <option value='{$vo['areaId']}' <if condition="$areaId1 == $vo['areaId'] ">selected</if>>{$vo['areaName']}</option>
               </volist>
             </select>
             <select id='areaId2' name='areaId2'>
               <option value=''>请选择</option>
             </select>
  商城分类：<select id='goodsCatId1' name='goodsCatId1' onchange='javascript:getCatList("goodsCatId2",this.value,0)'>
	                <option value='0'>请选择</option>
	                <volist name="goodsCatsList" id="vo">
	                <option value='{$vo['catId']}' <if condition="$goodsCatId1 == $vo['catId'] ">selected</if>>{$vo['catName']}</option>
	                </volist>
	             </select>
	             <select id='goodsCatId2' name='goodsCatId2' onchange='javascript:getCatList("goodsCatId3",this.value,1);'>
	                <option value='0'>请选择</option>
	             </select>
	             <select id='goodsCatId3' name='goodsCatId3'>
	                <option value='0'>请选择</option>
	             </select>
   </div>
   <div class='wst-tbar'>             
       所属店铺：<input type='text' id='shopName' name='shopName' value='{$shopName}'/>          
       商品：<input type='text' id='goodsName' name='goodsName' value='{$goodsName}'/> 
  <button type="submit" class="btn btn-primary glyphicon glyphicon-search">查询</button> 
       </div>
       </form>
       <div class='wst-body'>
        <table class="table table-hover table-striped table-bordered wst-list">
           <thead>
             <tr>
               <th width='30'>序号</th>
               <th width='150'>商品名称</th>
               <th width='60'>商品编号</th>
               <th width='100'>店铺</th>
               <th width='40'>秒杀价格</th>
               <th width='40'>状态</th>
               <th width='50'>开始日期</th>
               <th width='50'>结束日期</th>
               <th width='60'>开始抢购</th>
               <th width='50'>限购</th>
               <th width='100'>操作</th>
             </tr>
           </thead>
           <tbody>
            <volist name="Page['root']" id="vo" key='i'>
             <tr>
               <td><input type='checkbox' class='chk' name='chk_{$vo['goodsId']}' value='{$vo['goodsId']}'/>{$i}</td>
               <td img='{$vo['goodsThums']}' class='imgPreview'>
               <img src='__ROOT__/{$vo['goodsThums']}' width='50'/>
               {$vo['goodsName']}
               </td>
               <td>{$vo['goodsSn']}&nbsp;</td>
               <td><a href="{:U('Admin/Group/queryPenddingByPage',array('shopName'=>$vo['shopName']))}">{$vo['shopName']}</a>&nbsp;</td>
               <td>{$vo['seckillPrice']}&nbsp;</td>
               <td>
                   <if condition="$vo['goodsSeckillStatus'] eq 0">
                       审核中&nbsp;
                       <else/>
                       不通过&nbsp;
                   </if>

               </td>

               <td>{$vo['seckillStartTime']}</td>
               <td>{$vo['seckillEndTime']}</td>
               <td>
                 <if condition="$vo['seckillSetTime'] eq 1">
                  8:00
                  <elseif condition="$vo['seckillSetTime'] eq 2" />
                  12:00
                  <elseif condition="$vo['seckillSetTime'] eq 3" />
                  16:00
                  <elseif condition="$vo['seckillSetTime'] eq 4" />
                  20:00
                  <else />
                    00:00
                  </if>
               </td>
               <td>{$vo['seckillMaxCount']}</td>
               <td>
               <a class="btn btn-primary glyphicon" href='{:U("Admin/Seckill/toPenddingView",array("id"=>$vo["goodsId"]))}'>查看</a>
               <php>if(in_array('spsh_04',$WST_STAFF['grant'])){</php>
               <button type="button" class="btn btn-success glyphicon glyphicon" onclick="javascript:changeStatus({$vo['id']},1)">通过</button>&nbsp;
               <!--
               <button type="button" class="btn btn-danger glyphicon glyphicon-pencil" onclick="javascript:notPass({$vo['id']})">不通过</button>&nbsp;
               -->
               <php>}</php>
               </td>
             </tr>
             </volist>
             <tr>
                <td colspan='9' align='center'>{$Page['pager']}</td>
             </tr>
           </tbody>
        </table>
       </div>
    <script type="text/javascript">

        (function($) {
            $.extend({
                myTime: {
                    /**
                     * 当前时间戳
                     * @return <int>    unix时间戳(秒)
                     */
                    CurTime: function(){
                        return Date.parse(new Date())/1000;
                    },
                    /**
                     * 日期 转换为 Unix时间戳
                     * @param <string> 2014-01-01 20:20:20 日期格式
                     * @return <int>    unix时间戳(秒)
                     */
                    DateToUnix: function(string) {
                        var f = string.split(' ', 2);
                        var d = (f[0] ? f[0] : '').split('-', 3);
                        var t = (f[1] ? f[1] : '').split(':', 3);
                        return (new Date(
                                        parseInt(d[0], 10) || null,
                                        (parseInt(d[1], 10) || 1) - 1,
                                        parseInt(d[2], 10) || null,
                                        parseInt(t[0], 10) || null,
                                        parseInt(t[1], 10) || null,
                                        parseInt(t[2], 10) || null
                                )).getTime() / 1000;
                    },
                    /**
                     * 时间戳转换日期
                     * @param <int> unixTime  待时间戳(秒)
                     * @param <bool> isFull  返回完整时间(Y-m-d 或者 Y-m-d H:i:s)
                     * @param <int> timeZone  时区
                     */
                    UnixToDate: function(unixTime, isFull, timeZone) {
                        if (typeof (timeZone) == 'number')
                        {
                            unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
                        }
                        var time = new Date(unixTime * 1000);
                        var ymdhis = "";
                        ymdhis += time.getUTCFullYear() + "-";
                        var M=(time.getUTCMonth()+1);
                        if(M.toString().length==1)M='0'+M;
                        ymdhis += M + "-";
                        var D=(time.getUTCDate());
                        if(D.toString().length==1)D='0'+D;
                        ymdhis += D;
                        if (isFull === true)
                        {
                            var H=(time.getUTCHours());
                            if(H.toString().length==1)H='0'+H;
                            ymdhis += ' '+H+':00:00';
                        }
                        return ymdhis;
                    }
                }
            });
        })(jQuery);

        for(var i=1;i<15;i++){

            (function(i){
                jeDate({
                    dateCell:".startTime_"+i,
                    format:"YYYY-MM-DD hh:00:00",
                    isinitVal:false,
                    isTime:true, //isClear:false,
                    minDate:"2014-09-19 00:00:00",
                    choosefun:function(val) {
                        var house=val.split(':')[0].substr(-2,2);
                        if(house==00 || house==08 || house==12 || house==16 || house==20){
                            var temp=$.myTime.DateToUnix(val);
                            if(house==00){
                                temp=parseInt(temp+60*60*8);
                            }else{
                                temp=parseInt(temp+60*60*4);
                            }
                            temp=$.myTime.UnixToDate(temp,true,8);
                            $('.endTime_'+i).val(temp);
                        }else{
                            WST.msg('开始时间只能为：00:00,08:00,12:00,16:00,20:00!',{icon: 0});
                            $('.startTime_'+i).val('');
                            $('.endTime_'+i).val('');
                        }
                    },  //选中日期后的回调
                    clearfun:function(val) {$('.endTime_'+i).val('');},   //清除日期后的回调
                    okfun:function(val){
                        var house=val.split(':')[0].substr(-2,2);
                        if(house==00 || house==08 || house==12 || house==16 || house==20){
                            var temp=$.myTime.DateToUnix(val);
                            if(house==00){
                                temp=parseInt(temp+60*60*8);
                            }else{
                                temp=parseInt(temp+60*60*4);
                            }
                            temp=$.myTime.UnixToDate(temp,true,8);
                            $('.endTime_'+i).val(temp);
                        }else{
                            WST.msg('开始时间只能为：00:00,08:00,12:00,16:00,20:00!',{icon: 0});
                            $('.startTime_'+i).val('');
                            $('.endTime_'+i).val('');
                        }
                    }
                })
            })(i);
        }
    </script>
   </body>
</html>